package scyComposition

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"likeadmin/clog"
	"likeadmin/model"
	"likeadmin/sqlop"
	"net/http"
	"strconv"
)

func GetScyCompositionListSql(
	start int, end int) (string, string) {
	var condition = ""

	var countSql = "select count(1) as ct from scy_composition t where is_deleted=0 " + condition
	fmt.Println(countSql)
	clog.Info("scyComposition,GetScyCompositionListSql,countSql=", countSql)
	condition = condition + " limit " + strconv.Itoa(start) + "," + strconv.Itoa(end)
	var listSql = "select  * from scy_composition t where is_deleted=0 " + condition
	fmt.Println(listSql)
	clog.Print("scyComposition,GetScyCompositionListSql,listSql=", listSql)
	return countSql, listSql
}

func GetScyCompositionList(c *gin.Context) {
	getScyCompositionListCommon(c, "0")
}

type InputStruct struct {
	Page int `json:"page"`
	Size int `json:"size"`
}

func getScyCompositionListCommon(c *gin.Context, isInRecycle string) {
	var inputStruct InputStruct
	c.ShouldBind(&inputStruct)

	var count *int

	var list []model.ScyComposition

	var countSql, listSql = GetScyCompositionListSql((inputStruct.Page-1)*inputStruct.Size, inputStruct.Size)

	sqlop.QueryNoP(countSql, true).Scan(&count)

	sqlop.QueryNoP(listSql, true).Scan(&list)

	clog.Info("scyComposition,getScyCompositionListCommon,list=", list)
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"data": map[string]interface{}{
			"list":  list,
			"count": count,
		},
	})
}
